/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Server.lastproject;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JTree;
import javax.swing.tree.TreePath;

/**
 *
 * @author CANG
 */
public class MyPopupMenu_Root extends JPopupMenu
{
    private JMenuItem[] jmiItems;
    private ActionListener _jacl;
    private ServerForm _server;
    private JTree _jTreeTable;
    
    public MyPopupMenu_Root(ServerForm server, JTree jTreeTable)
    {
        _jTreeTable = jTreeTable;
        _server = server;
        
        jmiItems = new JMenuItem[2];
        
        jmiItems[0] = new JMenuItem("Create new Table");
        jmiItems[1] = new JMenuItem("Properties");
        
        for(int i = 0; i < jmiItems.length; i++)
        {
            add(jmiItems[i]);
        }
        
        _jacl = new ActionListener()
        {

            @Override
            public void actionPerformed(ActionEvent e)
            {
                TreePath tp = _jTreeTable.getSelectionPath();
                Object ob = tp.getLastPathComponent();
                String command = e.getActionCommand();
                char cCommand = command.charAt(0);
                switch(cCommand)
                {
                    case 'C':
                    {                        
                        _server.ShowInfo(ServerForm.TABLE_CREATE, null);
                        break;
                    }
                    
                        
                    case 'P':
                    {
                        //chưa xử lý...nếu còn time thì...
                        break;
                    }
                }
            }
        };
        
        for(int i = 0; i < jmiItems.length; i++)
        {
            jmiItems[i].addActionListener(_jacl);
        }
        
       
    }
}
